import { http } from "@/utils/http";
import type { ResultProps } from "@/api/user";

export interface PulperVersionListProp {
  id: number;
  accountId: number;
  businessId: number;
  name: string;
  note: null;
  deleteStatus: number;
  publishStatus: null;
  publishTime: null;
  deviceType: string;
  moduleKey: string;
  updateTime: Date;
  createTime: Date;
  customParameters: null;
}

export const pulperVersionGetList = (data?: object) => {
  return http.requestJson<ResultProps<PulperVersionListProp[]>>(
    "post",
    "/mash/formula/version/getList",
    {
      data
    }
  );
};

export const pulperVersionAdd = (data?: object) => {
  return http.requestJson<ResultProps<null>>(
    "post",
    "/mash/formula/version/add",
    {
      data
    }
  );
};

export const pulperVersionUpd = (data?: object) => {
  return http.requestJson<ResultProps<null>>(
    "post",
    "/mash/formula/version/upd",
    {
      data
    }
  );
};

export const pulperVersionDel = (data?: object) => {
  return http.requestJson<ResultProps<null>>(
    "post",
    "/mash/formula/version/del",
    {
      data
    }
  );
};

export const pulperVersionPublish = (data?: object) => {
  return http.requestJson<ResultProps<null>>(
    "post",
    "/mash/formula/version/publish",
    {
      data
    }
  );
};

export const pulperVersionRelease = (data?: object) => {
  return http.requestJson<ResultProps<null>>(
    "post",
    "/mash/formula/version/release",
    {
      data
    }
  );
};

export const pulperVersionGetReleaseList = (data?: object) => {
  return http.requestJson<ResultProps<any>>(
    "post",
    "/mash/formula/version/getReleaseList",
    {
      data
    }
  );
};

export interface PulperFormulaListProp {
  accountId?: number;
  businessId?: number;
  createTime?: string;
  deleteStatus?: number;
  deviceType?: string;
  formulaId?: string;
  formulaSubid?: string;
  icon?: string;
  id?: number;
  name?: string;
  note?: string;
  price?: number;
  publishStatus?: number;
  publishTime?: string;
  typeId?: number;
  updateTime?: string;
  versionId?: number;

  [property: string]: any;
}

export interface PulperFormulaAddModel {
  moduleFormula: ModuleFormula;
  specs: Spec[];

  [property: string]: any;
}

export interface ModuleFormula {
  /**
   * 配方id
   */
  formulaId?: string;
  /**
   * 子配方id唯一标识
   */
  formulaSubid?: string;
  /**
   * 配方主图
   */
  icon?: string;
  /**
   * 自增ID
   */
  id?: number;
  /**
   * 配方名称
   */
  name?: string;
  /**
   * 配方备注
   */
  note?: string;
  /**
   * 上架状态：0->下架；1->上架
   */
  publishStatus?: number;
  /**
   * 分类ID
   */
  typeId?: number;
  /**
   * 配方版本ID
   */
  versionId?: number;

  [property: string]: any;
}

export interface Spec {
  /**
   * 配方物料配比详情 jsonarray, jsonarray 字符串
   */
  details: string;
  /**
   * 规格id
   */
  specId: string;
  /**
   * 规格名称
   */
  specName: string;

  [property: string]: any;
}

export const pulperFormulaAdd = (data?: object) => {
  return http.requestJson<ResultProps<PulperFormulaListProp>>(
    "post",
    "/mash/formula/add",
    {
      data
    }
  );
};

export const pulperFormulaDel = (data?: object) => {
  return http.requestJson<ResultProps<PulperFormulaListProp>>(
    "post",
    "/mash/formula/del",
    {
      data
    }
  );
};

export const pulperFormulaUpd = (data?: object) => {
  return http.requestJson<ResultProps<PulperFormulaListProp>>(
    "post",
    "/mash/formula/upd",
    {
      data
    }
  );
};

export const pulperFormulaGetList = (data?: object) => {
  return http.requestJson<ResultProps<PulperFormulaListProp[]>>(
    "post",
    "/mash/formula/getList",
    {
      data
    }
  );
};

export const pulperFormulaPublish = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/mash/formula/publish", {
    data
  });
};

export interface PulperTypeListProp {
  accountId?: number;
  businessId?: number;
  createTime?: string;
  deleteStatus?: number;
  deviceType?: string;
  icon?: string;
  id?: number;
  moduleKey?: string;
  name?: string;
  note?: string;
  updateTime?: string;

  [property: string]: any;
}

export const pulperTypeGetList = (data?: object) => {
  return http.requestJson<ResultProps<PulperTypeListProp[]>>(
    "post",
    "/mash/formula/type/getList",
    {
      data
    }
  );
};

export const pulperTypeAdd = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/mash/formula/type/add", {
    data
  });
};

export const pulperTypeUpd = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/mash/formula/type/upd", {
    data
  });
};

export const pulperTypeDel = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/mash/formula/type/del", {
    data
  });
};
